package com.ssmoa.web.action.demo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.ssmoa.fm.springmvc.session.SessionContainer;
import com.ssmoa.utils.SSIConstants;
import com.ssmoa.web.action.demo.vo.UserVo;
import com.ssmoa.web.datastructure.AjaxJson;

@Controller
public class demoframe {

	/*
	 * 登录页面
	 */
	@RequestMapping(value="/demo/login")
	public String login(HttpServletRequest request,ModelMap model){
		System.out.println("登录页面");
		model.put("footinfo", "Copyright © 2018 XXXX");
		model.put("basePath", System.getProperty(SSIConstants.CONTENTPATH));
		return "/demo/login";
	}
	
	@RequestMapping(value="verityLogin",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String verifyLogin(HttpServletRequest request,ModelMap model,UserVo uvo){
		System.out.println("登录校验");
		AjaxJson aj = new AjaxJson();
		
		SessionContainer sessionContainer = (SessionContainer)request.getSession().
					getAttribute(SSIConstants.SESSIONCONTAINER);
		HttpSession session = request.getSession();
		if (null==sessionContainer) {
			sessionContainer = new SessionContainer();
		}
		sessionContainer.setUserName(uvo.getUserName());
		session.setAttribute(SSIConstants.SESSIONCONTAINER,
				sessionContainer);
		
		aj.setSuccess(true);
		aj.setMsg("处理成功");
		System.out.println(aj.getJsonStr());
		return aj.getJsonStr();
	}
	
	
    /*
     * 主框架
     */
	@RequestMapping(value="/demo/mainframe")
	public String mainframe (HttpServletRequest request,ModelMap model){
		System.out.println("主页面");
		SessionContainer sessionContainer = (SessionContainer)request.getSession().
		getAttribute(SSIConstants.SESSIONCONTAINER);	
		if(sessionContainer==null){
			model.put("userName", "无用户登录");
		}else{
			model.put("userName", sessionContainer.getUserName());
		}
		model.put("basePath", System.getProperty(SSIConstants.CONTENTPATH));
		return "/demo/mainframe";
	}
	
	@RequestMapping(value="/demo/admin_top")
	public String admin_top(HttpServletRequest request,ModelMap model){
		SessionContainer sessionContainer = (SessionContainer)request.getSession().
		getAttribute(SSIConstants.SESSIONCONTAINER);	
		if(sessionContainer==null){
			model.put("userName", "无用户登录");
		}else{
			model.put("userName", sessionContainer.getUserName());
		}
		model.put("basePath", System.getProperty(SSIConstants.CONTENTPATH));
		return "/demo/admin_top";
	}
	
	@RequestMapping(value="/demo/left")
	public String admin_left(HttpServletRequest request,ModelMap model){
		model.put("basePath", System.getProperty(SSIConstants.CONTENTPATH));
		return "/demo/left";
	}
	
	@RequestMapping(value="/demo/right")
	public String admin_right(HttpServletRequest request,ModelMap model){
		model.put("basePath", System.getProperty(SSIConstants.CONTENTPATH));
		return "/demo/right";
	}
	
	/*
	 * 表格
	 */
	@RequestMapping(value="/demo/table")
	public String grid(HttpServletRequest request,ModelMap mode){
		System.out.println("表格demo");
		return "/demo/table";
	}
}

